<#include "/layout/layout.ftl"/>
<@body>
<script src="/lib/ewin/ewin.js"></script>
    <div class="panel-body" style="padding-bottom:0px;">
        <div class="panel panel-default">
            <div class="panel-heading">查询条件</div>
            <div class="panel-body" style="padding:2px">
                <form id="formSearch" class="form-horizontal">
                    <div class="" style="margin-top:15px">
                        <label class="control-label col-sm-1" for="interfaceType">组件类型</label>
                        <div class="col-sm-3">
                            <select id="interfaceType" class="form-control" onchange="switchInterfaceType()">
                                <option value="dubbo">dubbo</option>
                                <option value="http">http</option>
                                <option value="webService">webService</option>
                                <option value="restful">restful</option>
                                <option value="mysql">mysql</option>
                                <option value="redis">redis</option>
                                <option value="mq">mq</option>
                            </select>
                        </div>
                        <div class="" style="margin-top:15px">
                            <label class="control-label col-sm-1" for="interfaceAliasName">组件别名</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" id="interfaceAliasName">
                            </div>
                            <div class="col-sm-4" style="text-align:left;">
                                <button type="button" style="margin-left:50px" id="btn_query" onclick="query()"
                                        class="btn btn-primary btnFont">
                                    查询
                                </button>
                            </div>
                        </div>
                </form>
            </div>
        </div>
        <div id="toolbar">
            <button id="btn_add" type="button" class="btn btn-default" onclick="openAddComponentPage()">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
            </button>
            <button id="btn_edit" type="button" class="btn btn-default" onclick="modifyComponent()">
                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
            </button>
            <button id="btn_delete" type="button" class="btn btn-default" onclick="deleteComponent()">
                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
            </button>
            <button id="btn_delete" type="button" class="btn btn-default" onclick="testCasePage()">
                <span class="glyphicon glyphicon-wrench" aria-hidden="true" ></span>维护测试用例
            </button>
            <button id="btn_delete" type="button" class="btn btn-default"  onclick="testCasePage()">
                <span class="glyphicon glyphicon-play" aria-hidden="true" ></span>执行组件测试
            </button>
        </div>
        <table id="dataTable"></table>
    </div>

<script type="text/javascript">

    function openAddComponentPage() {
        window.location.href = "/component/addComponentPage?interfaceType=" + $("#interfaceType").val();
    }
    function testCasePage() {
        var arrSelections=$("#dataTable").bootstrapTable("getSelections");
        if(arrSelections.length <=0){
            Ewin.alert("必须选择一条数据操作");
            return;
        }
        if(arrSelections.length >1){
            Ewin.alert("只能选择一个组件修改");
            return;
        }
        var id =arrSelections[0].id;
        window.location.href = "/testCase/testCasePage?interfaceId="+id+"&interfaceType=" + $("#interfaceType").val();
    }
    function query() {
        $("#dataTable").bootstrapTable("refresh")
    }

    function switchInterfaceType() {
        $("#dataTable").bootstrapTable("refresh");
    }
    
    function modifyComponent() {
       var arrSelections=$("#dataTable").bootstrapTable("getSelections");
        if(arrSelections.length <=0){
            Ewin.alert("必须选择一条数据操作");
            return;
        }
        if(arrSelections.length >1){
            Ewin.alert("只能选择一个组件修改");
            return;
        }
        var id =arrSelections[0].id;
        var interfaceType=$("#interfaceType").val();
        window.location.href="/component/addComponentPage?id="+id+"&interfaceType="+interfaceType;
    }
    function deleteComponent() {
        var arrSelections=$("#dataTable").bootstrapTable("getSelections");
        if(arrSelections.length <=0){
            Ewin.alert("必须选择一条数据操作");
            return;
        }
        if(arrSelections.length >1){
            Ewin.alert("只能选择一个组件修改");
            return;
        }
        var id =arrSelections[0].id;
        var interfaceType=$("#interfaceType").val();
        var url ="/component/deleteComponent";
        Ewin.confirm({message: "确认要组件吗?如果删除那么组件下的用例也会被删除"}).on(function (e) {
            if (!e) {
                return;
            }
            $.ajax({
                url:url,
                method:"post",
                data:{
                    id:id,
                    interfaceType:interfaceType
                },success:function (result) {
                    if(result.success){
                        $("#dataTable").bootstrapTable("refresh");
                    }else {
                        Ewin.alert(result.msg);
                    }
                }
            })
        });
    }


    function param(params) {
        var obj = {
            pageSize: params.limit,
            pageNum: (params.offset / params.limit) + 1,
            interfaceType: $("#interfaceType").val(),
            interfaceAliasName:$("#interfaceAliasName").val()
        };
        return obj;
    }

    $(function () {
        var interfaceUrl = "/component/componentList";
        $("#dataTable").bootstrapTable({
            url: interfaceUrl,
            method: "get",
            pageNumber: 1,
            pageSize: 10,
            pageList: [10, 20, 30, 40, 50],
            pagination: true,
            sidePagination: "server",
            cache: false,
            queryParams: param,
            height: 500,
            toolbar: "#toolbar",//这里面需要用到jquery的选择器
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            striped: true,
            showRefresh: true,
            clickToSelect: true,
            sortable: false,
            sortOrder: "asc",
            columns: [
                {
                    checkbox: true
                },
                {
                    "title": "接口别名",
                    "field": "interfaceAliasName"
                },
                {
                    "title": "接口名",
                    "field": "interfaceName"
                }, {
                    "title": "方法名",
                    "field": "interfaceMethod"
                },
                {
                    "title": "编码",
                    "field": "encoding"
                },
                {
                    "title": "超时(秒)",
                    "field": "timeout"
                },
                {
                    "title": "创建人",
                    "field": "userName"
                }
            ]
        })
    })
</script>

</@body>